package ywu.pocket;

import static android.content.Context.*;

import java.io.*;
import java.util.*;

import android.content.*;

public class BootEventReceiver extends BroadcastReceiver {

    

    @Override
    public void onReceive(final Context ctx, final Intent intent) {
        logBootEvent(ctx, intent);

        ctx.startService(new Intent("ywu.pocket.StartPocketModeService"));
    }

    private void logBootEvent(final Context ctx, final Intent intent) {
        try {
            doLogBootEvent(ctx, intent);
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }

    private void doLogBootEvent(final Context ctx, final Intent intent) throws IOException {
        PrintWriter out = null;
        try {
            out = new PrintWriter(ctx.openFileOutput("bootevent", MODE_PRIVATE | MODE_APPEND));
            out.format("[%s] onReceive intent=%s\n", new Date(), intent);
        }
        finally {
            if (out != null) out.close();
        }
    }
}
